package com.example.myapp4;

import android.graphics.Bitmap;
import android.nfc.Tag;
import android.util.Log;
import android.util.LruCache;

import com.android.volley.toolbox.ImageLoader;

import static com.android.volley.VolleyLog.TAG;


/**
 * Created by 杨劲宇 on 2019/6/27.
 */

class MyImageCache implements ImageLoader.ImageCache {
    private final  String TAG="MyImageCache";
    private LruCache<String,Bitmap>lruCache;
    public MyImageCache(){
        int maxsize=10*1024;

        lruCache=new LruCache<String, Bitmap>(maxsize){
            @Override
            protected int sizeOf(String key, Bitmap value) {
                return value.getRowBytes()*value.getHeight();
            }
        };
    }
    @Override
    public Bitmap getBitmap(String s) {
        Bitmap bitmap=lruCache.get(s);
        if (bitmap==null){

            Log.e(TAG,"getBitmap failed bitmap==null");
        }else {
            Log.e(TAG,"getBitmap failed bitmap!==null");
        }
        return lruCache.get(s);
    }

    @Override
    public void putBitmap(String s, Bitmap bitmap) {
        if (bitmap==null){

            Log.e(TAG,"getBitmap failed bitmap==null");
        }else {
            Log.e(TAG,"getBitmap failed bitmap!==null");
        }


        lruCache.put(s,bitmap);
    }
}
